package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ChangePoint;
import cn.wolfcode.crm.domain.Member;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.serivce.IChangePointService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("changePoint")
public class ChangePoitController {
    @Autowired
    private IChangePointService service;

    @RequestMapping("view")
    public String view() throws Exception {
        return "changePoint";
    }

    @RequestMapping("listAll")
    @ResponseBody
    public List<ChangePoint> listAll(QueryObject qo) throws Exception {
        List<ChangePoint> changePoints = service.selectAll();
        return changePoints;
    }
    @RequestMapping("addPoint")
    @ResponseBody
    public JSONResult addPoint(ChangePoint changePoint) throws Exception {
        try {
            service.addPoint(changePoint);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("操作失败!");
        }
    }
    @RequestMapping("removePoint")
    @ResponseBody
    public JSONResult removePoint(ChangePoint changePoint) throws Exception {
        try {
            service.removePoint(changePoint);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("操作失败!");
        }
    }
}
